package com.ross.mode;

/**
 * 双重锁的方式是方法级锁的优化，减少了部分获取实例的耗时。
 * 同时这种方式也满足了懒加载。
 *
 * @version 1.0.0
 * @className: User
 * @description: 双重锁校验(线程安全)
 * @author: zhangjunfa
 * @date: 2023/4/3 16:43
 */
public class User {
    private User() {
    }

    private volatile static User instance;

    public static User getInstance() {
        if (null != instance) {
            return instance;
        }
        synchronized (User.class) {
            if (null == instance) {
                instance = new User();
            }
        }
        return instance;
    }
}
